<?php
    include_once 'session_start.php';
    include_once 'database.php';
    $query = "SELECT * FROM borroweditem WHERE MaterialId=".$_GET["id"];
    $stmt =$db -> query($query);

    if($stmt -> num_rows >0){
        $_SESSION["H7_Library_Message"] = "Materialet var desværre allerede lånt ud";
    }else{            
        $query = "INSERT INTO borroweditem (UserId,MaterialId)
                  VALUES (".$_SESSION["User"]["Id"].",".$_GET["id"].");";
        $db -> query($query);
        
        $action = "Borrow";
        include 'item_history_db.php';
        
        $_SESSION["H7_Library_Message"] = "Det lykkedes at låne materialet";
    }

    header('Location:index.php');
?>